﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebCinesItech.Persistencia;
using WebCinesItech.Dominio;


namespace WebCinesItech
{
    public partial class About : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnRegistrar_Click(object sender, EventArgs e)
        {
            string usu = txtlogin.Text.Trim();
            string psw = txtcontras.Text.Trim();
            string psw2 = txtcontras2.Text.Trim();
            UsuarioDAO objDAO = new UsuarioDAO();
            if (ValidarRegistro(usu, psw, psw2)) {
                BE_Usuario objBE = new BE_Usuario();
                objBE.Usuario = usu;
                objBE.Password = psw;
                string res = objDAO.RegistrarUsuario(objBE);
                if (res != "") {
                    Session["Usuario"] = res;
                    Response.Redirect("frmReserva.aspx");
                }

            }
        }

        private bool ValidarRegistro(string usu, string psw, string psw2) {
            bool ret = true;
            if (usu != "" && psw != "" && psw2 != "")
            {
                if (usu.Length < 5)
                {
                    lbluser.Text = "*";
                    ret = false;
                }
                if (psw.Length < 5)
                {
                    lblpass.Text = "*";
                    ret = false;
                }
                if (psw2.Length < 5)
                {
                    lblpass2.Text = "*";
                    ret = false;
                }
                if (psw != psw2)
                {
                    lblpass2.Text = "*";
                    ret = false;
                }
            }
            else
            {
                if (usu == "")
                {
                    lbluser.Text = "*";
                }
                if (psw == "")
                {
                    lblpass.Text = "*";
                }
                if (psw2 == "")
                {
                    lblpass2.Text = "*";
                }
            }
            return ret;
        }
    }
}
